-
Notifications
You must be signed in to change notification settings - Fork 3
Allow compilation in absence of RS485 library #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -7,7 +7,7 @@ | |||
#include "Arduino_POSIXStorage.h" | |||
#include <iostream> | |||
|
|||
#if !defined(HAS_SERIAL) && defined(HAS_RS485) | |||
#if !defined(HAS_SERIAL) && defined(HAS_RS485) && __has_include(<ArduinoRS485.h>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately __has_include(<ArduinoRS485.h>)
will evaluate as false
even when the library is installed. the reason is that __has_include
checks whether the file is present in the compiler's "search path". Libraries are added to the search path by the "library discovery" phase of the Arduino sketch build system, which discovers libraries based on the #include
directives in the code. So there is a "Catch-22" situation when attempting to use __has_include
for conditional inclusion of headers from libraries:
You can check this with the following code:
#if __has_include(<ArduinoRS485.h>)
#pragma message "__has_include(<ArduinoRS485.h>) evaluated to true"
#else
#pragma message "__has_include(<ArduinoRS485.h>) evaluated to false"
#endif
When you compile, you will see the "__has_include(<ArduinoRS485.h>) evaluated to false
" message in the output even when the ArduinoRS485 library is installed.
The above is true for Arduino CLI and Arduino IDE. I don't have any experience with Arduino PLC IDE, so I can't say for sure but I would assume it is also true there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A workaround would be to add instructions for the user that, if they want to use the RS-485 debugging capabilities, they must add an #include
directive for ArduinoRS485.h
to their sketch above the #include
directive for the Arduino_UnifiedStorage library:
#include <ArduinoRS485.h>
#include <Arduino_UnifiedStorage.h>
This will cause the ArduinoRS485 library to be discovered and its path added to the search path before the evaluation of __has_include(<ArduinoRS485.h>)
, which will cause it to evaluate as true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@per1234 Well spotted! Your suggestion makes sense. Either we go with that, or we add ArduinoRS485 to the dependencies. I'd prefer not to because this dependency doesn't make sense for all boards. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to because this dependency doesn't make sense for all boards. Wdyt?
Since the library's "debugging output" feature is completely supplemental and likely to be used by advanced users who won't have difficulty installing the ArduinoRS485 library on demand, I think your perspective regarding avoiding the introduction of an additional dependency is reasonable.
This PR allows to compile on Opta without the need to install the ArduinoRS485 library. ArduinoRS485 is only needed for debugging USB storage which occupies the USB port so debug prints need to go through RS485.